<?php
/**
 * @package qBase
 * @subpackage web
 */

/**
 * The basic event object
 * 
 * @package qBase
 * @subpackage web
 */
class QWebEventStack extends QObject 
{
	/**
	 * if this variable is set to false it stops the propagation of the event
	 * this variable is se to false on each trigger
	 *
	 * @var boolean
	 */
	protected $events;

	/**
	 * The constructor of QEventStack
	 *
	 * @param array $events The list of events
	 */
	public function __construct($events = null)
	{
		parent::__construct();
		
		if ($events)
			$this->events = $events;
	}
	
	public function addEvent($sender_id, $event_type, $params = null)
	{
		if ((!isset($this->events)) || (!$this->events))
			$this->events = array();
			
		foreach ($this->events as $ev)
			if ($ev === $event)
				return;
				
		$this->events[] = array($sender_id, $event_type, $params);
	}
	
	public function countEvents()
	{
		if ((!isset($this->events)) || (!$this->events))
			return 0;
		else 
			return count($this->events);
	}
	
	public function getEventAt($pos)
	{
		if (isset($this->events) || (isset($this->events[$pos])))
			return $this->events[$pos];
		else 
			return null;
	}
	
	public function removeEvent($sender_id, $event_type)
	{
		if ((!isset($this->events)) || (!$this->events))
			return false;
		
		$c_ev = count($this->events);
		for ($i = 0; $i < $c_ev; $i++)
		{
			if (($this->events[$i][0] == $sender_id) && ($this->events[$i][1] == $event_type))
			{
				array_splice($this->events, $i, 1);
				return true;
			}
		}
		return false;
	}
}

?>